import axIos from 'axios';
import $md5 from 'js-md5';

/**
 * 获取当前用户信息
 * @returns {Promise<AxiosResponse<T>>}
 */
export function getMyInfo() {
    return axIos.get("/apis/cjlgb-design-upms/employee/getMyInfo");
}

/**
 * 认证接口
 * @param code
 * @param flag
 * @returns {Promise<AxiosResponse<T>>}
 */
export function grant(code,flag) {
    return axIos.get("/apis/cjlgb-design-upms/grant/" + code + "/" + flag);
}

/**
 * 绑定用户接口
 * @param params
 * @returns {Promise<AxiosResponse<T>>}
 */
export function binding(params) {
    //  将密码进行加密,并添加随机盐参数
    let salt = Date.now();
    params['password'] = $md5($md5(params['password']) + salt);
    params['salt'] = salt;
    return axIos.put("/apis/cjlgb-design-upms/grant/", params);
}

/**
 * 获取菜单树
 * @returns {Promise<AxiosResponse<T>>}
 */
export function getMenuTree() {
    return axIos.get("/apis/cjlgb-design-upms/menu/tree");
}

/**
 * 获取全部菜单树
 * @returns {Promise<AxiosResponse<T>>}
 */
export function getAllMenuTree() {
    return axIos.get("/apis/cjlgb-design-upms/menu/all/tree");
}

/**
 * 删除菜单
 * @param menuId
 * @returns {Promise<AxiosResponse<T>>}
 */
export function deleteMenu(menuId) {
    return axIos.delete("/apis/cjlgb-design-upms/menu/" + menuId);
}

/**
 * 添加系统菜单
 * @param params
 * @returns {Promise<AxiosResponse<T>>}
 */
export function addMenu(params) {
    return axIos.post("/apis/cjlgb-design-upms/menu",params);
}

/**
 * 修改系统菜单
 * @param params
 * @returns {Promise<AxiosResponse<T>>}
 */
export function editMenu(params) {
    return axIos.put("/apis/cjlgb-design-upms/menu",params);
}

/**
 * 查询系统权限列表
 * @param params
 * @returns {Promise<AxiosResponse<T>>}
 */
export function getPowerList(params) {
    return axIos.get("/apis/cjlgb-design-upms/power",{ params : params });
}

/**
 * 获取当前用户可见的权限树
 * @returns {Promise<AxiosResponse<T>>}
 */
export function getPowerListTree() {
    return axIos.get("/apis/cjlgb-design-upms/power/tree");
}

/**
 * 删除系统权限
 * @param powerId
 * @returns {Promise<AxiosResponse<T>>}
 */
export function deletePower(powerId) {
    return axIos.delete("/apis/cjlgb-design-upms/power/" + powerId);
}

/**
 * 修改系统权限
 * @param params
 * @returns {Promise<AxiosResponse<T>>}
 */
export function editPower(params) {
    return axIos.put("/apis/cjlgb-design-upms/power",params);
}

/**
 * 添加系统权限
 * @param params
 * @returns {Promise<AxiosResponse<T>>}
 */
export function addPower(params) {
    return axIos.post("/apis/cjlgb-design-upms/power",params);
}

/**
 * 查询系统角色列表
 * @param params
 * @returns {Promise<AxiosResponse<T>>}
 */
export function getRoleList(params) {
    return axIos.get("/apis/cjlgb-design-upms/role",{ params : params });
}

/**
 * 添加系统角色
 * @param params
 * @returns {Promise<AxiosResponse<T>>}
 */
export function addRole(params) {
    return axIos.post("/apis/cjlgb-design-upms/role",params);
}

/**
 * 修改系统角色
 * @param params
 * @returns {Promise<AxiosResponse<T>>}
 */
export function editRole(params) {
    return axIos.put("/apis/cjlgb-design-upms/role",params);
}

/**
 * 删除系统角色
 * @param roleId
 * @returns {Promise<AxiosResponse<T>>}
 */
export function deleteRole(roleId) {
    return axIos.delete("/apis/cjlgb-design-upms/role/" + roleId);
}

/**
 * 获取某角色的权限列表
 * @param roleId
 * @returns {Promise<AxiosResponse<T>>}
 */
export function getRoleAuthorities(roleId) {
    return axIos.get("/apis/cjlgb-design-upms/role/authorities/" + roleId);
}

/**
 * 修改某角色的权限列表
 * @param roleId
 * @param authorities
 * @returns {Promise<AxiosResponse<T>>}
 */
export function editRoleAuthorities(roleId,authorities) {
    return axIos.put("/apis/cjlgb-design-upms/role/authorities",{ id : roleId, authorities : authorities });
}

/**
 * 分页查询员工信息
 * @param params
 * @returns {Promise<AxiosResponse<T>>}
 */
export function getEmployeePage(params) {
    return axIos.get("/apis/cjlgb-design-upms/employee",{ params : params });
}

/**
 * 添加员工
 * @param params
 * @returns {Promise<AxiosResponse<T>>}
 */
export function addEmployee(params) {
    return axIos.post("/apis/cjlgb-design-upms/employee",params);
}

/**
 * 修改员工
 * @param params
 * @returns {Promise<AxiosResponse<T>>}
 */
export function editEmployee(params) {
    return axIos.put("/apis/cjlgb-design-upms/employee",params);
}

/**
 * 获取员工的角色Id列表
 * @param id
 * @returns {Promise<AxiosResponse<T>>}
 */
export function getEmployeeRoleIds(id) {
    return axIos.get("/apis/cjlgb-design-upms/employee/getRoleIds/" + id);
}

/**
 * 删除员工
 * @param id
 * @returns {Promise<AxiosResponse<T>>}
 */
export function deleteEmployee(id) {
    return axIos.delete("/apis/cjlgb-design-upms/employee/" + id);
}

/**
 * 查询部门列表
 * @returns {Promise<AxiosResponse<T>>}
 */
export function getDepartmentList() {
    return axIos.get("/apis/cjlgb-design-upms/department");
}

/**
 * 创建部门
 * @param params
 * @returns {Promise<AxiosResponse<T>>}
 */
export function addDepartment(params) {
    return axIos.post("/apis/cjlgb-design-upms/department",params);
}

/**
 * 修改部门
 * @param params
 * @returns {Promise<AxiosResponse<T>>}
 */
export function editDepartment(params) {
    return axIos.put("/apis/cjlgb-design-upms/department",params);
}

/**
 * 删除部门
 * @param deptId
 * @returns {Promise<AxiosResponse<T>>}
 */
export function deleteDepartment(deptId) {
    return axIos.delete("/apis/cjlgb-design-upms/department/" + deptId);
}
